package com.loadmore.oneday.adapter

import android.content.Context
import android.os.Bundle
import com.alibaba.android.arouter.launcher.ARouter
import com.loadmore.common.base.BaseAdapter
import com.loadmore.common.base.RVBaseHolder
import com.loadmore.common.model.Topic
import com.loadmore.common.router.RouterPath
import com.loadmore.oneday.R

/**
 *@author sunleilei
 *@date 2018/7/18
 *@time 16:22
 *
 */
class TopicListAdapter(context: Context) :BaseAdapter(context) {
    override fun getLayoutId(): Int {
        return R.layout.layout_topic_item
    }

    override fun onBindViewHolder(holder: RVBaseHolder<*>, position: Int) {
        val topic = getItem(position) as Topic
        holder.setText(R.id.title,topic.title).setText(R.id.content,topic.body)
                .setText(R.id.date,topic.getUpdated_at())
                .setText(R.id.reply_count,""+topic.replies_count)
                .setButton(R.id.category,topic.category.name)
        holder.itemView.setOnClickListener {

            var bundle = Bundle()
            bundle.putString("module",RouterPath.TopicDetail)
            bundle.putSerializable("data",topic)
            ARouter.getInstance().build(RouterPath.Module).with(bundle).navigation()
        }
    }

}